package com.yu.blog.entities.baseEntity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import java.io.Serializable;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Validated
@Accessors(chain = true)
@Schema(description = "共通数据")
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId(value = "id",type = IdType.ASSIGN_ID)
    @Schema(description = "ID")
    private String id;
    @Schema(description = "创建时间")
    @TableField(value = "create_time",fill= FieldFill.INSERT)
    @JsonFormat(pattern="yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    @Schema(description = "更新时间")
    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern="yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date updateTime;
    @Version
    @TableField(value ="version",fill= FieldFill.INSERT)
    @Schema(description = "乐观锁")
    private int version;
    @TableLogic
    @TableField(value ="deleted",fill= FieldFill.INSERT)
    @Schema(description = "悲观锁")
    private boolean deleted;
}